package com.lz.fruitday.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lz.fruitday.R;
import com.lz.fruitday.bean.FoodMainBean;
import com.lz.fruitday.utils.ImageLoaderUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by liuZhi
 * 2015/10/22
 */
public class FoodLvAdapter extends AppBaseAdapter<FoodMainBean> {
    private DisplayImageOptions options;
    public FoodLvAdapter(List<FoodMainBean> list, Context context) {
        super(list, context);
        options= ImageLoaderUtil.getDefaultOptions();
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        FoodMainBean mainBean=list.get(position);
        ViewHolder vh=ViewHolder.get(context,convertView,parent, R.layout.item_food_listview_layout);
        ImageView ivThums= (ImageView) vh.findViewById(R.id.iv_images_thumbs);
        TextView tvTitle= (TextView) vh.findViewById(R.id.tv_food_title);
        TextView tvSummary= (TextView) vh.findViewById(R.id.tv_food_summary);
        TextView tvTime= (TextView) vh.findViewById(R.id.tv_food_time);
        TextView tvWorth= (TextView) vh.findViewById(R.id.tv_worth_num);
        TextView tvComment= (TextView) vh.findViewById(R.id.tv_comment_num);

        ImageLoader.getInstance().displayImage(mainBean.getImages_thumbs(), ivThums, options);
        tvTitle.setText(mainBean.getTitle());
        tvSummary.setText(mainBean.getSummary());
        tvTime.setText((int) ((System.currentTimeMillis()-mainBean.getStime())/1000/60/60)+"小时前");
        tvWorth.setText(mainBean.getWorth_num());
        tvComment.setText(String.valueOf(mainBean.getComment_num()));
        return vh;
    }
}
